﻿using System;
using System.IO;
using LockerRack.Exceptions;
using LockerRack.Interfaces;

namespace TasksLib.DrawerStuff
{
    public class UnknownFile : IDrawerFileStuff
    {
        public string FilePath
        {
            get
            {
                if (PropertyBag is string)
                    return PropertyBag;

                return string.Empty;
            }
        }

        public void Dispose()
        {
            
        }

        public Guid Id { get; set; }
        public dynamic PropertyBag { get; set; }

        public UnknownFile()
        {
            Id = Guid.NewGuid();
        }

        public bool Load(string path, out LockerException lex)
        {
            lex = null;
            PropertyBag = path;
            return true;
        }

        public bool Save(string path, out LockerException lex)
        {
            lex = null;
            try
            {
                if(FilePath.Equals(path, StringComparison.OrdinalIgnoreCase))
                    return false;

                File.Copy(FilePath, path, true);
            }
            catch (Exception ex)
            {
                lex = new LockerException("Save error for unknown file", ex);
            }

            return lex == null;
        }

        public bool CreateDefaulContent(object data, out LockerException lex)
        {
            lex = null;
            return false;
        }
    }
}
